package com.paul.sys.util;

import com.paul.sys.model.Ptstaff;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import  java.util.List;

public class CommSession {

    public static void setMenu(HttpServletRequest request,List<String> menus){
        HttpSession session = request.getSession();
        session.setAttribute("menus",menus);
    }
   public static void setUser(HttpServletRequest request,Ptstaff staff){
       HttpSession session = request.getSession();
       session.setAttribute("user",staff);
   }
    public static Ptstaff getUser(HttpServletRequest request){
        HttpSession session = request.getSession();
        Object user = session.getAttribute("user");
        if(user!=null){
            return (Ptstaff)user;
        }
        return null;
    }
    public static void removeUser(HttpServletRequest request){
        HttpSession session = request.getSession();
        session.removeAttribute("user");
    }
    public static void removeSession(HttpServletRequest request){
        request.getSession().invalidate();
    }
    public static List<String> getMenu(HttpServletRequest reqeuest) {
        HttpSession session = reqeuest.getSession();
        Object menus = session.getAttribute("menus");
        if(menus!=null){
            return (List<String>)menus;
        }
        return null;
    }
}
